#define _CRT_SECURE_NO_WARNINGS #include #include #include typedef struct{ char name[100]; } element; typedef struct ListNode{ element data; struct ListNode *link; } ListNode; element delete_first(ListNode *head){ ListNode *removed; element data; if (head == (ListNode *)NULL) return; removed=head->link; data=removed->data; if(head==removed) head=NULL; else head->link=removed->link; free(removed); return data; } ListNode* insert_last(ListNode* head, element data){ ListNode *node = (ListNode *)malloc(sizeof(ListNode)); node->data = data; if (head == NULL) { head = node ; node->link = head; } else { node->link = head->link; head->link = node; head = node; } return head; } void print_list(ListNode* head){ ListNode* p; if (head == NULL) return; p = head->link; do { printf("%s->", p->data); p = p->link; } while (p!= head); printf("%s->", p->data); printf("\n"); } int main(void){ ListNode *head = NULL; element data; strcpy(data.name, "KIM"); head=insert_last(head, data); print_list(head); strcpy(data.name, "PARK"); head=insert_last(head, data); print_list(head); strcpy(data.name, "CHOI"); head=insert_last(head, data); print_list(head); data=delete_first(head); printf("%s\n", data.name); data=delete_first(head); printf("%s\n", data.name); data=delete_first(head); printf("%s\n", data.name); return 0; }